
/*
 *    Display Shower = show a display table
 *    
 *    To do : change the envent handling
 *    Add a way to compute width and heights of individual celle
 *    
 *    @author : J.J.G.
 */

package fr.emse.tatiana.display;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;
import javax.swing.table.TableColumn;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Date;
import java.awt.Color;
import javax.swing.ListSelectionModel;

public class DisplayShower  {
    private boolean DEBUG = false;

    public DisplayTable dt ;
    public DisplayTableModel dtm ;
    JFrame frame ;

    public DisplayShower(DisplayTable dtable)
    {


        dt = dtable ;
        dtm = new DisplayTableModel(dt);



      
        // Display only visible columns
        dt.colnb = dt.vcolnb;
        dtm.fireTableStructureChanged();

        evaluateWidth();
        
    }


    /**
     * Try to recompute adequate width for columns of the table.
     */
    public void evaluateWidth()
    {
        for (int nc = 0; nc< dt.colnb; nc++)
        {
            int hW, minW, maxW, pW;
            hW = ((Integer)dt.aux[DisplayTable.CHWidth][nc]).intValue();
            minW = ((Integer)dt.aux[DisplayTable.CmWidth][nc]).intValue();
            maxW = ((Integer)dt.aux[DisplayTable.CMWidth][nc]).intValue();
            pW = ((Integer)dt.aux[DisplayTable.CPWidth][nc]).intValue();
            if (minW < 4) minW = 4;
            if (maxW < minW) maxW = minW+4;
            if (maxW < hW +4) maxW = hW +4;
            if (maxW < 2*pW - minW) maxW = 2*pW - minW;
            pW = (minW+maxW)/2;
            if (pW < hW) pW = hW + 2;
            maxW = 3*maxW;  // temporairement
            if (maxW < 20) maxW = 20;
            // Save values
            dt.aux[DisplayTable.CmWidth][nc] = new Integer(minW);
            dt.aux[DisplayTable.CMWidth][nc] = new Integer(maxW);
            dt.aux[DisplayTable.CPWidth][nc] = new Integer(pW);

     	   if ((DisplayTable.DBG & DisplayTable.DBGcol) != 0)
     	   {
            System.out.println("  Columns size [" + nc + "]  =  "+ 
            		dt.aux[DisplayTable.CHWidth][nc] + ",  " +
            		dt.aux[DisplayTable.CmWidth][nc] + ",  " + 
            		dt.aux[DisplayTable.CMWidth][nc] + ",  " +
            		dt.aux[DisplayTable.CPWidth][nc]);
     	   }
        }
        
    }


}
